<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.dianPuMingCheng" placeholder="店铺名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.gongSiMingCheng" placeholder="公司名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.diQu" placeholder="地区" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.shiFouRenZheng" clearable  placeholder="是否认证">
          <el-option label="已认证" value='已认证'></el-option>
          <el-option label="未认证" value='未认证'></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.xiaoDianJieShao" placeholder="小店介绍" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.zhuYingPinZhong" placeholder="主营品种" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.lianXiRen" placeholder="联系人" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.lianXiFangShi" placeholder="联系方式" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.shenFenZhengHao" placeholder="身份证号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.jingYingDiZhi" placeholder="经营地址" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList(1)">查询</el-button>

      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        label="选中"
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        type="index"
        label="序号"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="dianPuMingCheng"
        header-align="center"
        align="center"
        label="店铺名称">
      </el-table-column>
<!--      <el-table-column
        prop="gongSiMingCheng"
        header-align="center"
        align="center"
        label="公司名称">
      </el-table-column>
      <el-table-column
        prop="diQu"
        header-align="center"
        align="center"
        label="地区">
      </el-table-column>-->
      <el-table-column
        prop="shiFouRenZheng"
        header-align="center"
        align="center"
        label="认证状态">
      </el-table-column>
      <el-table-column
        prop="zhuCeShiJian"
        header-align="center"
        align="center"
        label="注册时间">
      </el-table-column>
<!--      <el-table-column
        prop="xiaoDianJieShao"
        header-align="center"
        align="center"
        label="小店介绍">
      </el-table-column>
      <el-table-column
        prop="zhuYingPinZhong"
        header-align="center"
        align="center"
        label="主营品种">
      </el-table-column>-->
      <el-table-column
        prop="lianXiRen"
        header-align="center"
        align="center"
        label="联系人">
      </el-table-column>
      <el-table-column
        prop="lianXiFangShi"
        header-align="center"
        align="center"
        label="联系方式">
      </el-table-column>
      <el-table-column
        prop="xingBie"
        header-align="center"
        align="center"
        label="性别">
      </el-table-column>
<!--
      <el-table-column
        prop="leiXing"
        header-align="center"
        align="center"
        label="类型">
      </el-table-column>
      <el-table-column
        prop="gongSiZiZhi"
        header-align="center"
        align="center"
        label="公司资质">
      </el-table-column>
      <el-table-column
        prop="yingYeZhiZhao"
        header-align="center"
        align="center"
        label="营业执照">
      </el-table-column>
      <el-table-column
        prop="jianCeZhengShu"
        header-align="center"
        align="center"
        label="检测证书">
      </el-table-column>
      <el-table-column
        prop="gongSiZhaoPian"
        header-align="center"
        align="center"
        label="公司照片">
      </el-table-column>-->

      <el-table-column
        prop="shenFenZhengHao"
        header-align="center"
        align="center"
        label="身份证号">
      </el-table-column>
      <el-table-column
        prop="jingYingDiZhi"
        header-align="center"
        align="center"
        label="经营地址">
      </el-table-column>
      <el-table-column
        prop="shenHeShiJian"
        header-align="center"
        align="center"
        label="认证时间">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small"  v-if="scope.row.shiFouRenZheng !='已认证'"
                     @click="shenHe(scope.row.id)"><i class="el-icon-edit"></i>审核
          </el-button>
          <el-button type="text" size="small" v-if="scope.row.shiFouRenZheng =='已认证'"
                     @click="shenHe(scope.row.id)"><i class="el-icon-info"></i>详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 弹窗, 新增 / 修改 -->
    <el-dialog title="客户管理客户明细" :visible.sync="infoVisible">
      <div class="mod-config">
        <el-descriptions :column="2" title="基本信息" :colon="false" border content-class-name="customContent" label-class-name="customLable">
          <el-descriptions-item label="店铺名称">{{ this.infoList.dianPuMingCheng }}</el-descriptions-item>
          <el-descriptions-item label="公司名称">{{ this.infoList.gongSiMingCheng }}</el-descriptions-item>
          <el-descriptions-item label="地区">{{ this.infoList.diQu }}</el-descriptions-item>
          <el-descriptions-item label="是否认证">{{ this.infoList.shiFouRenZheng }}</el-descriptions-item>
          <el-descriptions-item label="注册时间">{{ this.infoList.zhuCeShiJian }}</el-descriptions-item>
          <el-descriptions-item label="小店介绍">{{ this.infoList.xiaoDianJieShao }}</el-descriptions-item>
          <el-descriptions-item label="主营品种">{{ this.infoList.zhuYingPinZhong }}</el-descriptions-item>
          <el-descriptions-item label="联系人">{{ this.infoList.lianXiRen }}</el-descriptions-item>
          <el-descriptions-item label="联系方式">{{ this.infoList.lianXiFangShi }}</el-descriptions-item>
          <el-descriptions-item label="性别">{{ this.infoList.xingBie }}</el-descriptions-item>
          <el-descriptions-item label="身份证号">{{ this.infoList.shenFenZhengHao }}</el-descriptions-item>
          <el-descriptions-item label="类型">{{ this.infoList.leiXing }}</el-descriptions-item>
<!--          <el-descriptions-item label="公司资质">{{ this.infoList.gongSiZiZhi }}</el-descriptions-item>
          <el-descriptions-item label="营业执照">{{ this.infoList.yingYeZhiZhao }}</el-descriptions-item>
          <el-descriptions-item label="检测证书">{{ this.infoList.jianCeZhengShu }}</el-descriptions-item>
          <el-descriptions-item label="公司照片">{{ this.infoList.gongSiZhaoPian }}</el-descriptions-item>-->
          <el-descriptions-item label="公司资质" >
            <img width="200px" height="200px" v-if="infoList.gongSiZiZhi" :src="this.$http.adornUrl('/api-file/file/view/file?fileId='+ this.infoList.gongSiZiZhi) ">
          </el-descriptions-item>
          <el-descriptions-item label="营业执照" >
            <img width="200px" height="200px" v-if="infoList.yingYeZhiZhao"  :src="this.$http.adornUrl('/api-file/file/view/file?fileId='+ this.infoList.yingYeZhiZhao) ">
          </el-descriptions-item>
          <el-descriptions-item label="检测证书" >
            <img width="200px" height="200px" v-if="infoList.jianCeZhengShu"  :src="this.$http.adornUrl('/api-file/file/view/file?fileId='+ this.infoList.jianCeZhengShu) ">
          </el-descriptions-item>
          <el-descriptions-item label="公司照片" >
            <img width="200px" height="200px" v-if="infoList.gongSiZhaoPian"  :src="this.$http.adornUrl('/api-file/file/view/file?fileId='+ this.infoList.gongSiZhaoPian) ">
          </el-descriptions-item>
          <el-descriptions-item label="经营地址">{{ this.infoList.jingYingDiZhi }}</el-descriptions-item>
        </el-descriptions>
          <div class="el-descriptions__title custom-title">审核信息</div>
           <div>
             <el-form :rules="dataRule" :model="dataSaveForm" ref="dataSaveForm" @keyup.enter.native="dataFormSubmit()">
               <el-form-item hidden :label-width="'120px'" prop="id">
                 <el-input v-model="dataSaveForm.id" autocomplete="off"></el-input>
               </el-form-item>
<!--               -->
               <el-form-item label="审核结果"  :label-width="'120px'" >
                 <el-select v-model="dataSaveForm.shenHeJieGuo" style="width: 100%" :disabled="isDisabled" clearable placeholder="请选择审核结果">
                   <el-option label="通过" value='通过'></el-option>
                   <el-option label="不通过" value='不通过'></el-option>
                 </el-select>
               </el-form-item>
               <el-form-item label="审核意见" :label-width="'120px'" prop="jingYingDiZhi">
                 <el-input v-model="dataSaveForm.shenHeYiJian" :disabled="isDisabled" type="textarea" autocomplete="off"></el-input>
               </el-form-item>
             </el-form>
           </div>


      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="qxinfo()">取 消</el-button>
        <el-button type="primary" @click="dataFormSubmit()">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import YaoCaiGongYing from './yaoCaiGongYing.vue'
import YaoCaiCaiGou from './yaoCaiCaiGou.vue'
export default {
  data() {
    return {
      dataForm: {
        dianPuMingCheng: '',
        gongSiMingCheng: '',
        diQu: '',
        shiFouRenZheng: '',
        zhuCeShiJian: '',
        xiaoDianJieShao: '',
        zhuYingPinZhong: '',
        lianXiRen: '',
        lianXiFangShi: '',
        xingBie: '',
        shenFenZhengHao: '',
        leiXing: '',
        gongSiZiZhi: '',
        yingYeZhiZhao: '',
        jianCeZhengShu: '',
        gongSiZhaoPian: '',
        jingYingDiZhi: '',
        guanLianYongHu: '',
      },
      activeName: 'first',
      dataSaveForm: {
        id:'',
        shenHeJieGuo: '',
        shenHeYiJian:'',

      },
      dataRule: {
        shenHeJieGuo: [
          {required: true, message: '不能为空', trigger: 'blur'}
        ],
        shenHeYiJian: [
          {required: true, message: '不能为空', trigger: 'blur'}
        ],

      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false,

      infoList: [],
      infoLoading: false,
      infoVisible: false,
      isDisabled:false
    }
  },
  components: {
    YaoCaiGongYing,
    YaoCaiCaiGou
  },

  activated() {
    this.dataForm.dianPuMingCheng=''
    this.dataForm.gongSiMingCheng=''
    this.dataForm.diQu=''
    this.dataForm.shiFouRenZheng=''
    this.dataForm.xiaoDianJieShao=''
    this.dataForm.zhuYingPinZhong=''
    this.dataForm.lianXiRen=''
    this.dataForm.lianXiFangShi=''
    this.dataForm.shenFenZhengHao=''
    this.dataForm.jingYingDiZhi=''
    this.getDataList()
  },
  methods: {
    shenHe(id){
      this.infoVisible = true;
      this.infoList = [];
      this.$nextTick(()=>{
        this.$refs['dataSaveForm'].resetFields()
      })

      this.$http({
        url: this.$http.adornUrl(`/api-trading/keHuGuanLi/keHuGuanLiKeHuMingXi/getById`),
        method: 'get',
        params: this.$http.adornParams({"id": id})
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.infoList = data.data;
          this.dataSaveForm.id = data.data.id
          this.dataSaveForm.shenHeJieGuo = data.data.shenHeJieGuo;
          this.dataSaveForm.shenHeYiJian = data.data.shenHeYiJian;
          if(this.infoList.shiFouRenZheng == '已认证'){
            this.isDisabled=true
          }
        }
      })

    },
    getDataList(pageIndex) {
      // this.$refs['dataForm'].resetFields()
      if (pageIndex) {
        this.pageIndex = pageIndex
      }
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/api-trading/keHuGuanLi/keHuGuanLiKeHuMingXi/list'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'dianPuMingCheng': this.dataForm.dianPuMingCheng,
          'gongSiMingCheng': this.dataForm.gongSiMingCheng,
          'diQu': this.dataForm.diQu,
          'shiFouRenZheng': this.dataForm.shiFouRenZheng,
          'zhuCeShiJian': this.dataForm.zhuCeShiJian,
          'xiaoDianJieShao': this.dataForm.xiaoDianJieShao,
          'zhuYingPinZhong': this.dataForm.zhuYingPinZhong,
          'lianXiRen': this.dataForm.lianXiRen,
          'lianXiFangShi': this.dataForm.lianXiFangShi,
          'xingBie': this.dataForm.xingBie,
          'shenFenZhengHao': this.dataForm.shenFenZhengHao,
          'leiXing': this.dataForm.leiXing,
          'gongSiZiZhi': this.dataForm.gongSiZiZhi,
          'yingYeZhiZhao': this.dataForm.yingYeZhiZhao,
          'jianCeZhengShu': this.dataForm.jianCeZhengShu,
          'gongSiZhaoPian': this.dataForm.gongSiZhaoPian,
          'jingYingDiZhi': this.dataForm.jingYingDiZhi,
          'guanLianYongHu': this.dataForm.guanLianYongHu,
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.data.records
          this.totalPage = Number(data.data.total)
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val
    },
    qx() {
      this.addOrUpdateVisible = false;

    },

    qxinfo() {
      this.infoVisible = false;

    },


    // 表单提交
    dataFormSubmit() {
      this.$refs['dataSaveForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/api-trading/keHuGuanLi/keHuGuanLiKeHuMingXi/shenHe`),
            method: 'post',
            data: this.$http.adornData({
              'id': this.dataSaveForm.id || undefined,
              'shenHeJieGuo': this.dataSaveForm.shenHeJieGuo,
              'shenHeYiJian': this.dataSaveForm.shenHeYiJian,
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.infoVisible = false
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })


    },
  }
}
</script>
<style>
.custom-title {
  color: #303133;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  margin-bottom: 20px;
  margin-top: 20px;
}

.customContent{
  color: rgb(19 35 29)
}
.customLable{
  color: rgb(19 35 29 / 77%);text-align:right;width:120px;background-color:#10592a0d;font-weight:bold
}

</style>
